package edu.ynu.se.xiecheng.achitectureclass.nongye.controller;

import edu.ynu.se.xiecheng.achitectureclass.nongye.dao.CameraDAO;
import edu.ynu.se.xiecheng.achitectureclass.nongye.entity.Camera;
import edu.ynu.se.xiecheng.achitectureclass.nongye.service.CameraService;
import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "相机管理")
@RestController
@RequestMapping("/camera")
public class CameraController extends LogicController<CameraService, CameraDAO, Camera, Integer> {

    @Autowired
    public CameraController(CameraService cameraService) {
        super(cameraService);
    }

    @ApiOperation("根据ID获取相机信息")
    @GetMapping("/getcamera")
    public Camera getCameraById(@RequestParam Integer id) {
        return getService().GET(id);
    }

    @ApiOperation("获取所有相机信息")
    @GetMapping("/getAllcamera")
    public List<Camera> getAllCamera() {
        return getService().getAll();
    }

    @ApiOperation("创建相机记录")
    @PostMapping("/postcamera")
    public Camera createCamera(@RequestBody Camera camera) {
        return getService().POST(camera);
    }

    @ApiOperation("更新相机记录")
    @PostMapping("/putcamera")
    public Camera updateCamera(@RequestBody Camera camera) {
        return getService().PUT(camera);
    }

    @ApiOperation("删除相机记录")
    @PostMapping("/deletecamera")
    public void deleteCamera(@RequestBody Camera camera) {
        getService().DELETE(camera);
    }

    @ApiOperation("通过ID删除相机记录")
    @GetMapping("/deleteByIdcamera")
    public void deleteCameraById(@RequestParam Integer id) {
        getService().DELETE(id);
    }
}
